home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.001 / tcpdump-~ / tcpdump-3.0.2-linux / libpcap-0.0.6 / mkdep < prev    next >
Encoding:
Text File  |  1995-04-21  |  2.2 KB  |  109 lines

  1. #!/bin/sh -
  2. #
  3. # Copyright (c) 1987 Regents of the University of California.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms are permitted
  7. # provided that this notice is preserved and that due credit is given
  8. # to the University of California at Berkeley. The name of the University
  9. # may not be used to endorse or promote products derived from this
  10. # software without specific prior written permission. This software
  11. # is provided ``as is'' without express or implied warranty.
  12. #
  13. #    @(#)mkdep.sh    5.11 (Berkeley) 5/5/88
  14. #
  15.  
  16. PATH=/bin:/usr/bin:/usr/ucb:/usr/local:/usr/local/bin
  17. export PATH
  18.  
  19. MAKE=Makefile            # default makefile name is "Makefile"
  20. CC=cc                # default C compiler is "cc"
  21.  
  22. while :
  23.     do case "$1" in
  24.         # -c allows you to specify the C compiler
  25.         -c)
  26.             CC=$2
  27.             shift; shift ;;
  28.  
  29.         # -f allows you to select a makefile name
  30.         -f)
  31.             MAKE=$2
  32.             shift; shift ;;
  33.  
  34.         # the -p flag produces "program: program.c" style dependencies
  35.         # so .o's don't get produced
  36.         -p)
  37.             SED='s;\.o;;'
  38.             shift ;;
  39.         *)
  40.             break ;;
  41.     esac
  42. done
  43.  
  44. if [ $# = 0 ] ; then
  45.     echo 'usage: mkdep [-p] [-c cc] [-f makefile] [flags] file ...'
  46.     exit 1
  47. fi
  48.  
  49. if [ ! -w $MAKE ]; then
  50.     echo "mkdep: no writeable file \"$MAKE\""
  51.     exit 1
  52. fi
  53.  
  54. TMP=/tmp/mkdep$$
  55.  
  56. trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
  57.  
  58. cp $MAKE ${MAKE}.bak
  59.  
  60. sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
  61.  
  62. cat << _EOF_ >> $TMP
  63. # DO NOT DELETE THIS LINE -- mkdep uses it.
  64. # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
  65.  
  66. _EOF_
  67.  
  68. # If your compiler doesn't have -M, add it.  If you can't, the next two
  69. # lines will try and replace the "cc -M".  The real problem is that this
  70. # hack can't deal with anything that requires a search path, and doesn't
  71. # even try for anything using bracket (<>) syntax.
  72. #
  73. # egrep '^#include[     ]*".*"' /dev/null $* |
  74. # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
  75.  
  76. $CC -M $* |
  77. sed "
  78.     s; \./; ;g
  79.     $SED" |
  80. awk '{
  81.     if ($1 != prev) {
  82.         if (rec != "")
  83.             print rec;
  84.         rec = $0;
  85.         prev = $1;
  86.     }
  87.     else {
  88.         if (length(rec $2) > 78) {
  89.             print rec;
  90.             rec = $0;
  91.         }
  92.         else
  93.             rec = rec " " $2
  94.     }
  95. }
  96. END {
  97.     print rec
  98. }' >> $TMP
  99.  
  100. cat << _EOF_ >> $TMP
  101.  
  102. # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
  103. _EOF_
  104.  
  105. # copy to preserve permissions
  106. cp $TMP $MAKE
  107. rm -f ${MAKE}.bak $TMP
  108. exit 0
  109.